package com.hankol.community.adapter

import android.app.Activity
import android.widget.RelativeLayout
import com.baselibrary.manager.SensorsDataManager
import com.baselibrary.utils.ARouterUtils
import com.baselibrary.utils.DoubleClickHelper
import com.baselibrary.utils.GlideUtils
import com.baselibrary.utils.ScreenUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.community.R
import com.hankol.community.bean.MajorPlateConfig
import com.hankol.community.bean.MajorPlateRule

/**
 * @author: yuyang、
 * @date: 2023/04/17
 * @Des：首页重点业务区 活动区
 */
class DiscoverPlateAdapter(var layoutId: Int, var datas: List<MajorPlateConfig>) : BaseQuickAdapter<MajorPlateConfig, BaseViewHolder>(layoutId, datas) {
    lateinit var rule: MajorPlateRule
    lateinit var activity: Activity
    var isImportant = false
    fun setShowRule(showRule: MajorPlateRule, isImportant: Boolean, activity: Activity) {
        this.rule = showRule
        this.isImportant = isImportant
        this.activity = activity
    }

    override fun convert(helper: BaseViewHolder, item: MajorPlateConfig) {
        if (rule != null) {
            helper.let {
                val root = it.getView<RelativeLayout>(R.id.rl_important)
                val p = root.layoutParams
                p.width = ((ScreenUtils.getScreenWidth() - ScreenUtils.dpToPx(28) - ScreenUtils.dpToPx(5 * (rule.composingType))).toFloat() / (rule.composingType + 1)).toInt()
                p.height = (p.width * rule.high.toFloat() / rule.wide).toInt()
                root.layoutParams = p
                it.setText(R.id.tv_important_title, item.name)
                it.setText(R.id.tv_important_content, item.name)
                GlideUtils.loadImg_228(mContext, item.img, it.getView(R.id.rci_cover))
                it.itemView.setOnClickListener {
                    if (!DoubleClickHelper.isOnDoubleClick()) {
                        if (isImportant) {
                            SensorsDataManager.instance.homeKeyClick(item.name)
                        } else {
                            SensorsDataManager.instance.homeChangqiClick(item.name)
                        }
                        ARouterUtils.bannerJump(activity, item.routeType, item.routeUrl, item.appletId)
                    }
                }
            }
        }
    }

}